﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataObject.DataAccess;
using DataObject.Database;

public partial class Pages_Reservations_Ascx_ProgramPopup : System.Web.UI.UserControl
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadServices();
            LoadProviders();
            LoadFields();
        }
    }
    #endregion

    #region Methods

    /// <summary>
    /// Load providers
    /// </summary>
    private void LoadProviders()
    {
        // Load Provider
        foreach (var item in ProviderDAO.CreateInstant().GetAll().OrderBy(x => x.ProviderName))
        {
            var listItem = new ListItem
            {
                Text = item.ProviderName,
                Value = item.ProviderID.ToString()
            };
            listItem.Attributes.Add("ProviderNumber", item.ProviderNumber);
            this.ddlProvider.Items.Add(listItem);
        }
    }

    /// <summary>
    /// Load services
    /// </summary>
    private void LoadServices()
    {
        // Load Service
        foreach (var item in ServiceDAO.CreateInstant().GetAll().OrderBy(x => x.ServiceName))
        {
            var listItem = new ListItem
            {
                Text = item.ServiceName,
                Value = item.ServiceID.ToString()
            };
            // -- Add Columns --
            listItem.Attributes.Add("ServiceCode", item.ServiceCode);
            listItem.Attributes.Add("ChoiceOption", item.ChoiceOption.ToString());
            listItem.Attributes.Add("Unit", item.Unit.ToString());
            listItem.Attributes.Add("NightFlag", item.NightFlag.ToString());
            listItem.Attributes.Add("NumInPackage", item.NumInPackage.ToString());
            listItem.Attributes.Add("PackagePrice", item.PackagePrice.ToString());
            listItem.Attributes.Add("UnitPrice", item.UnitPrice.ToString());
            listItem.Attributes.Add("OtherUom", item.OtherUom);
            listItem.Attributes.Add("Currency", item.Currency.ToString());

            // -- Add Row --
            this.ddlServiceName.Items.Add(listItem);
        }
    }

    /// <summary>
    /// Load fields
    /// </summary>
    private void LoadFields()
    {
        for (int i = 0; i < define.Services.Length; i++)
        {
            if (define.Services[i] == "None") continue;
            this.rdoServiceType.Items.Add(new ListItem
            {
                Value = i.ToString(),
                Text = define.Services[i],
                Selected = define.Services[i] == "Shared"
            });
        }

        this.ddlCurrencyType.Items.AddRange(DropDownListHelper.Currencies);
    }
    #endregion
}